package com.yxinsur.imc.web.controller.business;

import java.util.List;

import com.yxinsur.imc.business.domain.ImcRole;
import com.yxinsur.imc.business.form.ImcRoleForm;
import com.yxinsur.imc.business.service.IImcRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yxinsur.imc.common.annotation.Log;
import com.yxinsur.imc.common.core.controller.BaseController;
import com.yxinsur.imc.common.core.domain.AjaxResult;
import com.yxinsur.imc.common.enums.BusinessType;
import com.yxinsur.imc.common.utils.poi.ExcelUtil;
import com.yxinsur.imc.common.core.page.TableDataInfo;

/**
 * 代理人身份角色码Controller
 *
 * @author imc
 * @date 2021-04-13
 */
@Api(value="代理人身份角色接口服务",tags={"代理人角色[职级]接口服务"})
@RestController
@RequestMapping("/business/role")
public class ImcRoleController extends BaseController
{
    @Autowired
    private IImcRoleService imcRoleService;

    /**
     * 查询代理人身份角色码列表
     */
    //@PreAuthorize("@ss.hasPermi('system:role:list')")
    @ApiOperation("查询角色信息")
    @Log(title = "查询角色信息", businessType = BusinessType.INSERT)
    @GetMapping("/list")
    public TableDataInfo list()
    {
        startPage();
        List<ImcRole> list = imcRoleService.selectImcRoleList(new ImcRole());
        return getDataTable(list);
    }


    /**
     * 获取代理人身份角色码详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:role:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(imcRoleService.selectImcRoleById(id));
    }

    /**
     * 新增代理人身份角色码
     */
    @ApiOperation("新增角色信息")
    @Log(title = "新增角色信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody ImcRoleForm imcRoleForm) {
        return toAjax(imcRoleService.insertImcRole(imcRoleForm));
    }

    /**
     * 修改代理人身份角色码
     */
    @ApiOperation("修改角色信息")
    @Log(title = "代理人身份角色码", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody ImcRoleForm imcRoleForm)
    {
        return toAjax(imcRoleService.updateImcRole(imcRoleForm));
    }

    /**
     * 删除代理人身份角色码
     */
    @ApiOperation("删除角色信息")
    @Log(title = "代理人身份角色码", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        int deleteNum = imcRoleService.deleteImcRoleByIds(ids);
        return deleteNum > 0 ? AjaxResult.success() : AjaxResult.error("当前角色有成员，无法删除");

    }
}
